package xps.and.uudaijia.userclient.presenter;

import android.os.Bundle;
import android.support.annotation.NonNull;
import icepick.Icepick;
import nucleus.presenter.RxPresenter;
import nucleus.view.ViewWithPresenter;
import rx.functions.Action1;

public class BasePresenter<V extends ViewWithPresenter> extends RxPresenter<V> {
    @Override
    protected void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        Icepick.restoreInstanceState(this, savedState);
    }

    @Override
    protected void onSave(@NonNull Bundle state) {
        super.onSave(state);
        Icepick.saveInstanceState(this, state);

    }

    public void deliver(@NonNull Action1<? super V> onNext, @NonNull Action1<Throwable> onError) {
        view().filter(v -> v != null)
                .take(1)
                .subscribe(onNext, onError);
    }

}
